function tc(s, f5, fun) {
    var d = dialog({
        title: '提示',
        content: s,
        okValue: '确定',
        ok: function () {
            if (fun)eval(fun);
            if (f5 == true)
                location.href = location.href;
        },
    });
    d.show();
}
var CreatedOKLodop7766 = null;
//====判断是否需要安装CLodop云打印服务器:====
function needCLodop() {
    try {
        var ua = navigator.userAgent;
        if (ua.match(/Windows\sPhone/i) != null) return true;
        if (ua.match(/iPhone|iPod/i) != null) return true;
        if (ua.match(/Android/i) != null) return true;
        if (ua.match(/Edge\D?\d+/i) != null) return true;

        var verTrident = ua.match(/Trident\D?\d+/i);
        var verIE = ua.match(/MSIE\D?\d+/i);
        var verOPR = ua.match(/OPR\D?\d+/i);
        var verFF = ua.match(/Firefox\D?\d+/i);
        var x64 = ua.match(/x64/i);
        if ((verTrident == null) && (verIE == null) && (x64 !== null))
            return true; else if (verFF !== null) {
            verFF = verFF[0].match(/\d+/);
            if ((verFF[0] >= 42) || (x64 !== null)) return true;
        } else if (verOPR !== null) {
            verOPR = verOPR[0].match(/\d+/);
            if (verOPR[0] >= 32) return true;
        } else if ((verTrident == null) && (verIE == null)) {
            var verChrome = ua.match(/Chrome\D?\d+/i);
            if (verChrome !== null) {
                verChrome = verChrome[0].match(/\d+/);
                if (verChrome[0] >= 42) return true;
            }
            ;
        }
        ;
        return false;
    } catch (err) {
        return true;
    }
    ;
};

//====页面引用CLodop云打印必须的JS文件：====
if (needCLodop()) {
    var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
    var oscript = document.createElement("script");
    oscript.src = "http://localhost:8000/CLodopfuncs.js?priority=1";
    head.insertBefore(oscript, head.firstChild);

    //引用双端口(8000和18000）避免其中某个被占用：
    oscript = document.createElement("script");
    oscript.src = "http://localhost:18000/CLodopfuncs.js?priority=0";
    head.insertBefore(oscript, head.firstChild);
}
;

//====获取LODOP对象的主过程：====
function getLodop(oOBJECT, oEMBED) {
    var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='/static/lodop/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='/static/lodop/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
    var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='/static/lodop/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='/static/lodop/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
    var strHtmFireFox = "<br><br><font color='#FF00FF'>（注意：如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它）</font>";
    var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常，仅因浏览器升级或重安装而出问题，需重新执行以上安装）</font>";
    var strCLodopInstall = "<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='/static/lodop/CLodop_Setup_for_Win32NT.exe' target='_self'>执行安装</a>,安装后请刷新页面。</font>";
    var strCLodopUpdate = "<br><font color='#FF00FF'>CLodop云打印服务需升级!点击这里<a href='/static/lodop/CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
    var LODOP;
    try {
        var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
        if (needCLodop()) {
            try {
                LODOP = getCLodop();
            } catch (err) {
            }
            ;
            if (!LODOP && document.readyState !== "complete") {
                alert("C-Lodop没准备好，请稍后再试！");
                return;
            }
            ;
            if (!LODOP) {
                if (isIE) document.write(strCLodopInstall); else
                    document.documentElement.innerHTML = strCLodopInstall + document.documentElement.innerHTML;
                return;
            } else {

                if (CLODOP.CVERSION < "2.0.9.4") {
                    if (isIE) document.write(strCLodopUpdate); else
                        document.documentElement.innerHTML = strCLodopUpdate + document.documentElement.innerHTML;
                }
                ;
                if (oEMBED && oEMBED.parentNode) oEMBED.parentNode.removeChild(oEMBED);
                if (oOBJECT && oOBJECT.parentNode) oOBJECT.parentNode.removeChild(oOBJECT);
            }
            ;
        } else {
            var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
            //=====如果页面有Lodop就直接使用，没有则新建:==========
            if (oOBJECT != undefined || oEMBED != undefined) {
                if (isIE) LODOP = oOBJECT; else  LODOP = oEMBED;
            } else if (CreatedOKLodop7766 == null) {
                LODOP = document.createElement("object");
                LODOP.setAttribute("width", 0);
                LODOP.setAttribute("height", 0);
                LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
                if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
                else LODOP.setAttribute("type", "application/x-print-lodop");
                document.documentElement.appendChild(LODOP);
                CreatedOKLodop7766 = LODOP;
            } else LODOP = CreatedOKLodop7766;
            //=====Lodop插件未安装时提示下载地址:==========
            if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
                if (navigator.userAgent.indexOf('Chrome') >= 0)
                    document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
                if (navigator.userAgent.indexOf('Firefox') >= 0)
                    document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
                if (is64IE) document.write(strHtm64_Install); else if (isIE)   document.write(strHtmInstall); else
                    document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
                return LODOP;
            }
            ;
        }
        ;
        if (LODOP.VERSION < "6.2.1.7") {
            if (needCLodop())
                document.documentElement.innerHTML = strCLodopUpdate + document.documentElement.innerHTML; else if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
                document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
            return LODOP;
        }
        ;
        //===如下空白位置适合调用统一功能(如注册语句、语言选择等):===

        //===========================================================
        return LODOP;
    } catch (err) {
        alert("getLodop出错:" + err);
    }
    ;
};
function print_ugx(id) {
    $.ajax({
        url: '/ugx/print_ugx',
        type: 'POST',
        data: {id: id},
        dataType: 'JSON',
        cache: false,
        success: function (obj) {
            LODOP = getLodop();
            if (!LODOP)return;
            LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
            var st_ugx = ugxsign(obj.ugx.ugx);
            for (var i = 1; i < 2; i++) {
                LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/pt_ugx5.png?s=3'>");
                LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                LODOP.SET_PRINT_STYLE('FontName', 'Arial');
                LODOP.SET_PRINT_STYLE('Bold', '1');
                //UGX
                LODOP.SET_PRINT_STYLE('FontSize', '12.5');
                LODOP.ADD_PRINT_TEXT("30.5mm", "148mm", "100mm", "8mm", st_ugx);
                LODOP.SET_PRINT_STYLE('FontSize', '7');
                //条码
                LODOP.ADD_PRINT_BARCODE("15mm", "124mm", "72mm", "13mm", "Code39", obj.ugx.ugx);
                //日期--年月日
                LODOP.SET_PRINT_STYLE('FontSize', '7.5');
                LODOP.ADD_PRINT_TEXT("36mm", "73mm", "18mm", "2mm", obj.ugx.year);
                LODOP.ADD_PRINT_TEXT("36mm", "90mm", "9mm", "2mm", obj.ugx.month);
                LODOP.ADD_PRINT_TEXT("36mm", "105mm", "9mm", "2mm", obj.ugx.day);
                //UGX总重量
                LODOP.SET_PRINT_STYLE('FontSize', '16');
                LODOP.ADD_PRINT_TEXT("42mm", "125mm", "60mm", "12mm", obj.goods_weight);
                //包装尺寸
                LODOP.SET_PRINT_STYLE('FontSize', '14');
                LODOP.ADD_PRINT_TEXT("42mm", "160mm", "60mm", "12mm", obj.ugx.sizes[0]);
                LODOP.ADD_PRINT_TEXT("42mm", "170mm", "60mm", "12mm", obj.ugx.sizes[1]);
                LODOP.ADD_PRINT_TEXT("42mm", "183mm", "60mm", "12mm", obj.ugx.sizes[2]);
                //UGX货物总件数
                LODOP.ADD_PRINT_TEXT("77mm", "186mm", "10mm", "5mm", obj.child_num);
                //shipper信息
                LODOP.SET_PRINT_STYLE('FontSize', '9');
                LODOP.SET_PRINT_STYLE('Bold', '0');
                LODOP.ADD_PRINT_TEXT("40mm", "10mm", "50mm", "8mm", obj.shipper.from_nam);
                LODOP.ADD_PRINT_TEXT("44mm", "10mm", "50mm", "8mm", obj.shipper.from_companyName);
                LODOP.ADD_PRINT_TEXT("48mm", "10mm", "50mm", "8mm", obj.shipper.from_add1);
                LODOP.ADD_PRINT_TEXT("52mm", "10mm", "50mm", "8mm", obj.shipper.from_add2);
                LODOP.ADD_PRINT_TEXT("70mm", "10mm", "50mm", "8mm", obj.shipper.from_add3);
                LODOP.ADD_PRINT_TEXT("75.5mm", "80mm", "50mm", "8mm", obj.shipper.from_postal);
                LODOP.ADD_PRINT_TEXT("75.5mm", "20mm", "50mm", "8mm", obj.shipper.city);
                LODOP.ADD_PRINT_TEXT("80mm", "20mm", "50mm", "8mm", obj.shipper.tel);
                //consingnee信息
                LODOP.SET_PRINT_STYLE('FontSize', '8');
                LODOP.ADD_PRINT_TEXT("96mm", "10mm", "50mm", "8mm", obj.consingnee.to_nam);
                LODOP.ADD_PRINT_TEXT("100mm", "10mm", "50mm", "8mm", obj.consingnee.to_companyName);
                LODOP.ADD_PRINT_TEXT("104mm", "10mm", "50mm", "8mm", obj.consingnee.to_add1);
                LODOP.ADD_PRINT_TEXT("108mm", "10mm", "50mm", "8mm", obj.consingnee.to_add2_a);
                LODOP.ADD_PRINT_TEXT("112mm", "10mm", "50mm", "8mm", obj.consingnee.to_add2_b);
                LODOP.ADD_PRINT_TEXT("116mm", "10mm", "50mm", "8mm", obj.consingnee.to_add3);
                LODOP.ADD_PRINT_TEXT("124.5mm", "20mm", "30mm", "8mm", obj.consingnee.to_tel);
                //Contry信息
                LODOP.SET_PRINT_STYLE('Bold', '1');
                LODOP.ADD_PRINT_TEXT("134mm", "55mm", "80mm", "8mm", obj.contry);
                //BSO信息
                LODOP.SET_PRINT_STYLE('FontSize', '6');

                // var bos_num = obj.BSO.length;
                // bos_num = bos_num*-1;
                $.each(obj.BSO, function (index, itemobj) {
                    var step = 96 + 3.5 * (index - 1);
                    LODOP.ADD_PRINT_TEXT(step + "mm", "67mm", "100mm", "8mm", itemobj);
                });
                //LODOP.SET_PRINT_STYLE(-8,'ItemLetterSpacing ');
                //内容品详细==主单号商品
                LODOP.SET_PRINT_STYLE('FontSize', '9');
                $.each(obj.maininfo, function (index, itemobj) {
                    var step = 90 + 4.9 * index;
                    if (index < 6) {
                        LODOP.ADD_PRINT_TEXT(step + "mm", "114mm", "100mm", "8mm", itemobj.ename);
                        LODOP.ADD_PRINT_TEXT(step + "mm", "177mm", "100mm", "8mm", 'JPY');
                        var price_all_len = (itemobj.price_all + '').length;
                        LODOP.ADD_PRINT_TEXT(step + "mm", (196 - price_all_len * 2) + "mm", "100mm", "8mm", itemobj.price_all);
                    }
                });
                LODOP.SET_PRINT_STYLE('FontSize', '8');
                if (obj.maininfo_num > 6) {
                    LODOP.ADD_PRINT_TEXT("117.5mm", "114mm", "100mm", "8mm", 'FOR DETAILS.SEE ATTACHED DOCUMENT');
                }
                LODOP.SET_PRINT_STYLE('FontSize', '9');
                //损害要偿价格
                var goods_price_all_len = (obj.goods_price_all + '').length;
                LODOP.ADD_PRINT_TEXT("125mm", (196 - goods_price_all_len * 2) + "mm", "50mm", "8mm", obj.goods_price_all);
                //报税总价
                LODOP.ADD_PRINT_TEXT("133mm", (196 - goods_price_all_len * 2) + "mm", "50mm", "8mm", obj.goods_price_all);
                if (i != 3) {
                    LODOP.NEWPAGE();
                }
            }
            LODOP.PREVIEW();
        }
    });
}
function print_shipping(id) {
    $.ajax({
        url: '/ugx/print_ugx',
        type: 'POST',
        data: {id: id},
        dataType: 'JSON',
        cache: false,
        success: function (obj) {
            LODOP = getLodop();
            if (!LODOP)return;
            LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A4");
            LODOP.SET_PRINT_STYLE('FontName', 'Arial');
            $.each(obj.child, function (index, itemobj) {
                if (index % 5 == 1) {
                    if (index == 1) {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "297mm", "210mm", "<img border='0' src='/static/ugx/prt_shipping_a2.png?s=3'>");
                    } else {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "297mm", "210mm", "<img border='0' src='/static/ugx/prt_shipping_b1.png?s=3'>");
                    }
                    LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.SET_PRINT_STYLE('FontSize', '7.5');
                    var fan_num = Math.ceil(index / 5);
                    if ((fan_num + '').length == 1) {
                        fan_num = '0' + fan_num;
                    }
                    //BizCode
                    LODOP.ADD_PRINT_TEXT("8.3mm", "38mm", "75mm", "15mm", obj.bizCode);
                    //番号
                    LODOP.ADD_PRINT_TEXT("12mm", "38mm", "25mm", "15mm", obj.ugx.time + '-' + fan_num);
                    //日期
                    LODOP.ADD_PRINT_TEXT("8.2mm", "258mm", "50mm", "15mm", obj.ugx.year + '/' + obj.ugx.month + '/' + obj.ugx.day);
                    //页码
                    LODOP.SET_PRINT_STYLE('FontSize', '10');
                    LODOP.ADD_PRINT_TEXT("188mm", "265mm", "25mm", "3mm", Math.ceil(index / 5) + '  /  ' + Math.ceil(obj.child_num / 5));
                    LODOP.SET_PRINT_STYLE('FontSize', '7.5');
                }
                if (index == 1) {
                    //地址信息
                    $.each(obj.consingnee, function (index, itemobj) {
                        if (index == 'to_tel') {
                            LODOP.ADD_PRINT_TEXT("72mm", "90mm", "100mm", "8mm", itemobj);
                        } else if (index == 'to_add1') {
                            LODOP.ADD_PRINT_TEXT("56mm", "90mm", "100mm", "8mm", itemobj);
                        } else if (index == 'to_add2_a') {
                            LODOP.ADD_PRINT_TEXT("58.9mm", "90mm", "100mm", "8mm", itemobj);
                        } else if (index == 'to_add2_b') {
                            LODOP.ADD_PRINT_TEXT("61.8mm", "90mm", "100mm", "8mm", itemobj);
                        } else if (index == 'to_add3') {
                            LODOP.ADD_PRINT_TEXT("64.7mm", "90mm", "100mm", "8mm", itemobj);
                        }
                    });
                    //国家信息
                    LODOP.ADD_PRINT_TEXT("56mm", "148mm", "20mm", "25mm", obj.contry);
                    //内容品详细
                    LODOP.SET_PRINT_STYLE('FontSize', '6.5');
                    $.each(obj.maininfo, function (index, itemobj) {
                        var step = 52 + 4.5 * index;
                        if (index < 6) {
                            LODOP.ADD_PRINT_TEXT(step + "mm", "167.5mm", "40mm", "4.5mm", itemobj.ename);
                            LODOP.ADD_PRINT_TEXT(step + "mm", "207mm", "40mm", "4.5mm", 'JPY');
                            var price_all_len = (itemobj.price_all + '').length;
                            LODOP.ADD_PRINT_TEXT(step + "mm", (220.6 - (price_all_len - 1) * 1.4) + "mm", "40mm", "4.5mm", itemobj.price_all);
                        }
                    });
                    //报税价格
                    var goods_price_all_len = (obj.goods_price_all + '').length;
                    LODOP.ADD_PRINT_TEXT("56.7mm", (236.5 - (goods_price_all_len - 1) * 1.3) + "mm", "18mm", "3mm", obj.goods_price_all);
                    //损害要偿价格
                    LODOP.ADD_PRINT_TEXT("69.7mm", (236.5 - (goods_price_all_len - 1) * 1.3) + "mm", "18mm", "3mm", obj.goods_price_all);
                    //UGX总重量
                    var goods_weight_len = (obj.goods_weight + '').length;
                    LODOP.ADD_PRINT_TEXT("56.7mm", (252.5 - (goods_weight_len - 1) * 1.25) + "mm", "18mm", "3mm", obj.goods_weight);
                    //UGX主单号尺寸
                    LODOP.ADD_PRINT_TEXT("56.7mm", "258mm", "18mm", "3mm", obj.ugx.sizes[0] + '×' + obj.ugx.sizes[1] + '×' + obj.ugx.sizes[2]);
                }
                LODOP.SET_PRINT_STYLE('FontSize', '7.2');
                var step = 52 + ((index - 1) % 5) * 26.8;
                var step2 = step + 4;
                var step3 = 61 + ((index - 1) % 5) * 26.8;
                var step4 = step3 + 2;
                LODOP.ADD_PRINT_TEXT(step + "mm", "16.5mm", "25mm", "3mm", itemobj);
                LODOP.ADD_PRINT_TEXT(step2 + "mm", "20.5mm", "25mm", "3mm", 'UGX(物品)');
                LODOP.ADD_PRINT_TEXT(step2 + "mm", "12mm", "25mm", "3mm", index);
                LODOP.ADD_PRINT_TEXT(step + "mm", "39mm", "100mm", "3mm", obj.consingnee.to_companyName + "  NKG");
                LODOP.ADD_PRINT_TEXT(step2 + "mm", "39mm", "30mm", "3mm", obj.consingnee.to_nam);
                LODOP.ADD_PRINT_BARCODE(step3 + "mm", "18.5mm", "68mm", "15mm", "Code39", itemobj);
                if (index > 1) {
                    LODOP.SET_PRINT_STYLE('FontSize', '13');
                    LODOP.ADD_PRINT_TEXT(step4 + "mm", "100mm", "40mm", "3mm", '複数個口（子）');
                    LODOP.ADD_PRINT_TEXT(step4 + "mm", "150mm", "25mm", "3mm", index + ' / ' + obj.child_num);
                }
                if (index % 5 == 0 && obj.child_num > index) {
                    LODOP.NEWPAGE();
                }
            });
            LODOP.PREVIEW();
        }
    });
}
function print_receive(id) {
    $.ajax({
        url: '/ugx/print_ugx',
        type: 'POST',
        data: {id: id},
        dataType: 'JSON',
        cache: false,
        success: function (obj) {
            LODOP = getLodop();
            if (!LODOP)return;
            LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
            LODOP.SET_PRINT_STYLE('FontName', 'Arial');
            $.each(obj.child, function (index, itemobj) {
                if (index % 50 == 1) {
                    if (index == 1) {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/prt_receive_a1.png?s=3'>");
                    } else if (index == 51) {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/prt_receive_b1.png?s=3'>");
                    }
                    LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.SET_PRINT_STYLE('FontSize', '9');
                    var fan_num = Math.ceil(index / 50);
                    if ((fan_num + '').length == 1) {
                        fan_num = '0' + fan_num;
                    }
                    //BizCode
                    LODOP.ADD_PRINT_TEXT("23.5mm", "28mm", "90mm", "3mm", obj.bizCode);
                    //番号
                    LODOP.ADD_PRINT_TEXT("28.2mm", "28mm", "30mm", "3mm", obj.ugx.time + '-' + fan_num);
                    //日期
                    LODOP.ADD_PRINT_TEXT("21mm", "179mm", "50mm", "3mm", obj.ugx.year + '/' + obj.ugx.month + '/' + obj.ugx.day);
                    //页码
                    LODOP.SET_PRINT_STYLE('FontSize', '11');
                    LODOP.ADD_PRINT_TEXT("274mm", "187mm", "25mm", "3mm", Math.ceil(index / 50) + '  /  ' + Math.ceil(obj.child_num / 50));
                    LODOP.SET_PRINT_STYLE('FontSize', '7.5');
                }
                if (index == 1) {
                    //UGX主号码
                    LODOP.SET_PRINT_STYLE('FontSize', '9');
                    LODOP.ADD_PRINT_TEXT("84mm", "33.2mm", "35mm", "3mm", obj.ugx.ugx);
                    //UGX总重量
                    var goods_weight_len = (obj.goods_weight + '').length;
                    LODOP.ADD_PRINT_TEXT("84mm", (74.8 - (goods_weight_len - 1) * 1.8) + "mm", "30mm", "3mm", obj.goods_weight);
                    //UGX主单尺寸
                    LODOP.ADD_PRINT_TEXT("84mm", "82mm", "30mm", "3mm", obj.ugx.sizes[0] + '×' + obj.ugx.sizes[1] + '×' + obj.ugx.sizes[2]);
                } else {
                    LODOP.SET_PRINT_STYLE('FontSize', '9');
                    if (index > 1 && index < 26) {
                        var step1 = 84 + 7.5 * ((index - 1) % 25);
                        var step2 = 33.2;
                        var step3 = 68;
                        var step4 = 78;
                    } else if ((index > 25 && index < 51) || (index > 75 && index < 100)) {
                        var step1 = 84 + 7.5 * ((index - 1) % 25);
                        var step2 = 130.5;
                        var step3 = 164.5;
                        var step4 = 174.5;
                    } else if (index > 50 && index < 100) {
                        var step1 = 84 + 7.5 * ((index - 1) % 25);
                        var step2 = 33.2;
                        var step3 = 68;
                        var step4 = 78;
                    }
                    LODOP.ADD_PRINT_TEXT(step1 + "mm", step2 + "mm", "30mm", "3mm", itemobj);
                    LODOP.ADD_PRINT_TEXT(step1 + "mm", step3 + "mm", "30mm", "3mm", '—');
                    if ((index + '').length == 1) {
                        var index_num = ' ' + index;
                    } else {
                        var index_num = index;
                    }
                    if ((obj.child_num + '').length == 1) {
                        var child_num_num = ' ' + obj.child_num;
                    } else {
                        var child_num_num = obj.child_num;
                    }
                    LODOP.ADD_PRINT_TEXT(step1 + "mm", step4 + "mm", "30mm", "3mm", '複数個口(' + index_num + '/' + child_num_num + ')');
                    if (index == 50) {
                        LODOP.NEWPAGE();
                    }
                }
            });
            LODOP.PREVIEW();
        }
    });
}
function print_invoice(id) {
    $.ajax({
        url: '/ugx/print_ugx',
        type: 'POST',
        data: {id: id},
        dataType: 'JSON',
        cache: false,
        success: function (obj) {
            LODOP = getLodop();
            if (!LODOP)return;
            LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
            LODOP.SET_PRINT_STYLE('FontName', 'Arial');
            LODOP.SET_PRINT_STYLE('Bold', '1');
            LODOP.SET_PRINT_STYLE('FontSize', '8');
            $.each(obj.goods, function (index, itemobj) {
                if (index == 1) {
                    if (obj.goods_cat_num < 21) {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/pt_invoice31.png?s=3'>");
                    } else {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/pt_invoice_21.png?s=3'>");
                    }
                    LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    //日期
                    LODOP.ADD_PRINT_TEXT("38.4mm", "149mm", "50mm", "3mm", obj.ugx.year + '/' + obj.ugx.month + '/' + obj.ugx.day);
                    //UGX号码
                    LODOP.SET_PRINT_STYLE('FontSize', '14');
                    LODOP.ADD_PRINT_TEXT("49mm", "140mm", "50mm", "4mm", obj.ugx.ugx);
                    //shipper信息
                    LODOP.SET_PRINT_STYLE('FontSize', '9');
                    LODOP.SET_PRINT_STYLE('Bold', '0');
                    LODOP.ADD_PRINT_TEXT("53.5mm", "15mm", "50mm", "8mm", obj.shipper.from_nam);
                    LODOP.ADD_PRINT_TEXT("57.5mm", "15mm", "50mm", "8mm", obj.shipper.from_companyName);
                    LODOP.ADD_PRINT_TEXT("61.5mm", "15mm", "50mm", "8mm", obj.shipper.from_add1);
                    LODOP.ADD_PRINT_TEXT("65.5mm", "15mm", "50mm", "8mm", obj.shipper.from_add2);
                    LODOP.ADD_PRINT_TEXT("73mm", "15mm", "50mm", "8mm", obj.shipper.from_add3);
                    LODOP.ADD_PRINT_TEXT("84.5mm", "17mm", "30mm", "8mm", obj.shipper.city + ",JAPAN");
                    LODOP.ADD_PRINT_TEXT("88.8mm", "30mm", "30mm", "8mm", obj.shipper.from_postal);
                    LODOP.ADD_PRINT_TEXT("88.8mm", "73mm", "30mm", "8mm", obj.shipper.tel);
                    //consingnee信息
                    LODOP.ADD_PRINT_TEXT("103mm", "15mm", "50mm", "8mm", obj.consingnee.to_nam);
                    LODOP.ADD_PRINT_TEXT("107mm", "15mm", "50mm", "8mm", obj.consingnee.to_companyName);
                    LODOP.ADD_PRINT_TEXT("111mm", "15mm", "70mm", "8mm", obj.consingnee.to_add1);
                    LODOP.ADD_PRINT_TEXT("115mm", "15mm", "50mm", "8mm", obj.consingnee.to_add2_a);
                    LODOP.ADD_PRINT_TEXT("119mm", "15mm", "50mm", "8mm", obj.consingnee.to_add2_b);
                    LODOP.ADD_PRINT_TEXT("123mm", "15mm", "50mm", "8mm", obj.consingnee.to_add3);
                    LODOP.ADD_PRINT_TEXT("128mm", "18mm", "70mm", "8mm", obj.contry);
                    LODOP.ADD_PRINT_TEXT("132mm", "73mm", "70mm", "8mm", obj.consingnee.to_tel);
                    //Instruction
                    LODOP.SET_PRINT_STYLE('FontSize', '9');
                    LODOP.ADD_PRINT_TEXT('112mm', "108mm", "100mm", "4mm", obj.invoice[0]);
                    LODOP.ADD_PRINT_TEXT('117mm', "108mm", "100mm", "4mm", obj.invoice[1]);
                    LODOP.ADD_PRINT_TEXT('122mm', "108mm", "100mm", "4mm", obj.invoice[2]);
                    //页码
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.SET_PRINT_STYLE('FontSize', '11');
                    LODOP.ADD_PRINT_TEXT("274mm", "100mm", "25mm", "3mm", '1  /  1');
                } else if ((index - 20) % 45 == 1 && index > 20) {
                    if ((obj.goods_cat_num - index) > 44) {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/pt_invoice_a.png?s=3'>");
                        LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    } else {
                        LODOP.ADD_PRINT_IMAGE("0mm", "0mm", "210mm", "297mm", "<img border='0' src='/static/ugx/pt_invoice_b3.png?s=3'>");
                        LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    }
                    //页码
                    LODOP.SET_PRINT_STYLE('FontSize', '11');
                    LODOP.ADD_PRINT_TEXT("274mm", "187mm", "25mm", "3mm", (Math.ceil((index - 20) / 45) + 1) + '  /  ' + (Math.ceil((obj.goods_cat_num - 20) / 45) + 1));
                }
            });
            LODOP.SET_PRINT_STYLE('Bold', '0');
            LODOP.SET_PRINT_STYLE('FontSize', '8');
            $.each(obj.goods, function (index, itemobj) {
                if (index < 21) {
                    var step = 149 + 4.9 * (index - 1);
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "87.5mm", "15mm", "4mm", 'JAPAN');
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "150.5mm", "15mm", "4mm", 'JPY');
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "170.5mm", "15mm", "4mm", 'JPY');
                    //名称
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "10.5mm", "70mm", "4mm", itemobj.ename);
                    //重量
                    var weight_len = (itemobj.weight + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (123.5 - (weight_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.weight);
                    //数量
                    var num_len = (itemobj.num + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (146.5 - (num_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.num);
                    //单价
                    var price_len = (itemobj.price + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (166.7 - (price_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.price);
                    //总价
                    var price_all_len = (itemobj.price_all + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (193 - (price_all_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.price_all);
                    if (index == 20 && obj.goods_cat_num > 25) {
                        LODOP.NEWPAGE();
                    }
                } else {
                    var next_step = (index - 20) % 45;
                    var step = 26 + 4.9 * (next_step - 1);
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "87.5mm", "15mm", "4mm", 'JAPAN');
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "150.5mm", "15mm", "4mm", 'JPY');
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "170.5mm", "15mm", "4mm", 'JPY');
                    //名称
                    LODOP.ADD_PRINT_TEXT(step + 'mm', "10.5mm", "70mm", "4mm", itemobj.ename);
                    //重量
                    var weight_len = (itemobj.weight + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (123.5 - (weight_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.weight);
                    //数量
                    var num_len = (itemobj.num + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (146.5 - (num_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.num);
                    //单价
                    var price_len = (itemobj.price + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (166.7 - (price_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.price);
                    //总价
                    var price_all_len = (itemobj.price_all + '').length;
                    LODOP.ADD_PRINT_TEXT(step + 'mm', (193 - (price_all_len - 1) * 1.58) + "mm", "20mm", "4mm", itemobj.price_all);
                }
                if (index == obj.goods_cat_num) {
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.SET_PRINT_STYLE('FontSize', '8');
                    //总计价格
                    var goods_price_all_len = (obj.goods_price_all + '').length;
                    LODOP.ADD_PRINT_TEXT('248.5mm', (193 - (goods_price_all_len - 1) * 1.7) + "mm", "20mm", "4mm", obj.goods_price_all);
                    //商品总个数
                    var goods_nums_len = (obj.goods_nums + '').length;
                    LODOP.ADD_PRINT_TEXT('260.5mm', (75 - (goods_nums_len - 1) * 1.8) + "mm", "20mm", "4mm", obj.goods_nums);
                    //商品总净重
                    var goods_weight_len = (obj.goods_weight + '').length;
                    LODOP.ADD_PRINT_TEXT('266.5mm', (75 - (goods_weight_len - 1) * 1.58) + "mm", "30mm", "4mm", obj.goods_weight);
                }
                if ((index - 20) % 45 == 0 && obj.goods_cat_num > index) {
                    LODOP.NEWPAGE();
                }
            });
            LODOP.PREVIEW();
        }
    });
}
function print_child(id) {
    $.ajax({
        url: '/ugx/print_ugx',
        type: 'POST',
        data: {id: id},
        dataType: 'JSON',
        cache: false,
        success: function (obj) {
            var res = ugxsign(obj.ugx.ugx);
            LODOP = getLodop();
            if (!LODOP)return;
            LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A4");
            LODOP.SET_PRINT_STYLE('FontName', 'Arial');
            $.each(obj.child, function (index, itemobj) {
                if (index == 1) {
                    LODOP.ADD_PRINT_IMAGE("10mm", "11.5mm", "129.5mm", "90mm", "<img border='0' src='/static/ugx/child/bb.png?s=3'>");
                    LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    LODOP.SET_PRINT_STYLE('FontSize', '7');
                    $.each(obj.child, function (a, b) {
                        var chl = ugxsign(b);
                        if (a < 26) {
                            var hei = 27 + (a - 1) * 2.85;
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "12mm", "10mm", "8mm", a + '.');
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "18mm", "60mm", "8mm", chl);
                        } else if (a < 51 && a > 25) {
                            var hei = 27 + (a - 26) * 2.85;
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "44.5mm", "10mm", "8mm", a + '.');
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "50.5mm", "60mm", "8mm", chl);
                        } else if (a < 76 && a > 50) {
                            var hei = 27 + (a - 51) * 2.85;
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "78.5mm", "10mm", "8mm", a + '.');
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "84.5mm", "60mm", "8mm", chl);
                        } else if (a < 100 && a > 75) {
                            var hei = 27 + (a - 76) * 2.85;
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "111mm", "10mm", "8mm", a + '.');
                            LODOP.ADD_PRINT_TEXT(hei + "mm", "117mm", "60mm", "8mm", chl);
                        }
                    });
                    //UGX总数
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.SET_PRINT_STYLE('FontSize', '35');
                    LODOP.ADD_PRINT_TEXT("8mm", "130mm", "26mm", "18mm", obj.child_num);
                } else {
                    if (index % 4 == 1) {
                        var site_pic = [10, 9, 133, 90];
                        var site_ugx_code_main = [14, 74, 68, 14];
                        var site_ugx_code_child = [88, 64, 12.5, 12.5];
                        var site_ugx_main = [95.6, 34.5];
                        var site_ugx_child = [10, 115.5];
                        var site_date = [33.5, 55, 64, 71];
                        if (index < 10) {
                            var num_left = [28.5, 113];
                        } else {
                            var num_left = [28.5, 105];
                        }
                        var num_right = [28.5, 127];
                        //shipper上边距，左边距，consingnee上边距，contry上边距，contry左边距，
                        var tep = [36.5, 16, 65.5, 85.3, 42];
                    } else if (index % 4 == 2) {
                        var site_pic = [10, 155, 133, 90];
                        var site_ugx_code_main = [14, 220, 68, 14];
                        var site_ugx_code_child = [88, 210, 12.5, 12.5];
                        var site_ugx_main = [95.6, 180.5];
                        var site_ugx_child = [10, 261.5];
                        var site_date = [33.5, 201, 210, 217];
                        if (index < 10) {
                            var num_left = [28.5, 259];
                        } else {
                            var num_left = [28.5, 251];
                        }
                        var num_right = [28.5, 273];
                        //shipper上边距，左边距，consingnee上边距，contry上边距，contry左边距，
                        var tep = [36.5, 162, 65.5, 85.3, 188];
                    } else if (index % 4 == 3) {
                        var site_pic = [110, 9, 133, 90];
                        var site_ugx_code_main = [114, 74, 68, 14];
                        var site_ugx_code_child = [188, 64, 12.5, 12.5];
                        var site_ugx_main = [195.6, 34.5];
                        var site_ugx_child = [110, 115.5];
                        var site_date = [133.5, 55, 64, 71];
                        if (index < 10) {
                            var num_left = [128.5, 113];
                        } else {
                            var num_left = [128.5, 105];
                        }
                        var num_right = [128.5, 127];
                        //shipper上边距，左边距，consingnee上边距，contry上边距，contry左边距，
                        var tep = [136.5, 16, 165.5, 185.3, 42];
                    } else if (index % 4 == 0) {
                        var site_pic = [110, 155, 133, 90];
                        var site_ugx_code_main = [114, 220, 68, 14];
                        var site_ugx_code_child = [188, 210, 12.5, 12.5];
                        var site_ugx_main = [195.6, 180.5];
                        var site_ugx_child = [110, 261.5];
                        var site_date = [133.5, 201, 210, 217];
                        if (index < 10) {
                            var num_left = [128.5, 259];
                        } else {
                            var num_left = [128.5, 251];
                        }
                        var num_right = [128.5, 273];
                        //shipper上边距，左边距，consingnee上边距，contry上边距，contry左边距，
                        var tep = [136.5, 162, 165.5, 185.3, 188];
                    }
                    LODOP.ADD_PRINT_IMAGE(site_pic[0] + "mm", site_pic[1] + "mm", site_pic[2] + "mm", site_pic[3] + "mm", "<img border='0' src='/static/ugx/child/aa1.png?s=3'>");
                    LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
                    //UGX主号码
                    LODOP.SET_PRINT_STYLE('FontSize', '9.5');
                    LODOP.ADD_PRINT_TEXT(site_ugx_main[0] + "mm", site_ugx_main[1] + "mm", "60mm", "8mm", res);
                    //UGX子单码
                    LODOP.SET_PRINT_STYLE('FontSize', '8');
                    var chl = ugxsign(itemobj);
                    LODOP.ADD_PRINT_TEXT(site_ugx_child[0] + "mm", site_ugx_child[1] + "mm", "60mm", "8mm", chl);
                    //UGX子单号条形码
                    LODOP.SET_PRINT_STYLE('FontSize', '7.5');
                    LODOP.ADD_PRINT_BARCODE(site_ugx_code_main[0] + "mm", site_ugx_code_main[1] + "mm", site_ugx_code_main[2] + "mm", site_ugx_code_main[3] + "mm", "Code39", itemobj);
                    //UGX主单号二维码
                    LODOP.ADD_PRINT_BARCODE(site_ugx_code_child[0] + "mm", site_ugx_code_child[1] + "mm", site_ugx_code_child[2] + "mm", site_ugx_code_child[3] + "mm", "QRCode", obj.ugx.ugx);
                    //日期
                    LODOP.ADD_PRINT_TEXT(site_date[0] + "mm", site_date[1] + "mm", "10mm", "8mm", obj.ugx.year);
                    LODOP.ADD_PRINT_TEXT(site_date[0] + "mm", site_date[2] + "mm", "10mm", "8mm", obj.ugx.month);
                    LODOP.ADD_PRINT_TEXT(site_date[0] + "mm", site_date[3] + "mm", "10mm", "8mm", obj.ugx.day);
                    //发件人信息
                    LODOP.SET_PRINT_STYLE('FontSize', '5');
                    LODOP.SET_PRINT_STYLE('Bold', '0');
                    //shipper信息
                    var teps = tep[0];
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.from_nam);
                    teps = tep[0] + 1.9 * 1;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.from_companyName);
                    teps = tep[0] + 1.9 * 2;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.from_add1);
                    teps = tep[0] + 1.9 * 3;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.from_add2);
                    teps = tep[0] + 1.9 * 3 + 8.5;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.from_add3);
                    teps = tep[0] + 1.9 * 3 + 10.5;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.city);
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + 38 + "mm", "50mm", "8mm", obj.shipper.from_postal);
                    teps = tep[0] + 1.9 * 3 + 13;
                    LODOP.ADD_PRINT_TEXT(teps + "mm", tep[1] + "mm", "50mm", "8mm", obj.shipper.tel);
                    //consingnee信息
                    var tep3 = tep[2];
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_nam);
                    tep3 = tep[2] + 1.9 * 1;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_companyName);
                    tep3 = tep[2] + 1.9 * 2;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_add1);
                    tep3 = tep[2] + 1.9 * 3;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_add2_a);
                    tep3 = tep[2] + 1.9 * 4;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_add2_b);
                    tep3 = tep[2] + 1.9 * 5;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_add3);
                    tep3 = tep[2] + 1.9 * 5 + 4.3;
                    LODOP.ADD_PRINT_TEXT(tep3 + "mm", tep[1] + "mm", "50mm", "8mm", obj.consingnee.to_tel);
                    //contry信息
                    LODOP.SET_PRINT_STYLE('Bold', '1');
                    LODOP.ADD_PRINT_TEXT(tep[3] + "mm", tep[4] + "mm", "50mm", "8mm", obj.contry);
                    //编号
                    LODOP.SET_PRINT_STYLE('FontSize', '35');
                    LODOP.ADD_PRINT_TEXT(num_left[0] + "mm", num_left[1] + "mm", "26mm", "18mm", index);
                    LODOP.ADD_PRINT_TEXT(num_right[0] + "mm", num_right[1] + "mm", "26mm", "18mm", obj.child_num);
                    if (index % 4 == 0 && obj.child_num > index) {
                        LODOP.NEWPAGE();
                    }
                }
            });
            LODOP.PREVIEW();
        }
    });
}
function ugxsign(ugx) {
    var len = ugx.length;
    var head = ugx.substr(0, 2);
    var last = ugx.substr(len - 2, len - 1);
    var mid = ugx.substr(2, len - 4);
    var mid_len = mid.length;
    var nums = Math.ceil(mid_len / 3);
    var arr = new Array();
    for (var i = 0; i < nums; i++) {
        var ss = mid.substr(0 + (i * 3), 3);
        arr[i] = ss;
    }
    var res = new Object();
    res.head = head;
    res.last = last;
    res.mid = arr;
    var res2 = res.head + ' ' + arr[0] + ' ' + arr[1] + ' ' + arr[2] + ' ' + res.last;
    return res2;
}